from flask_restful import Resource, reqparse

from restful.api__.session import admin_required_current_admin_generate, pid_required_target_post_generate
from restful.model.query import QueryOneInstance
from restful.model.update import UpdateInstance
from restful.response import ResponseSuccess


class Check(Resource):
    @admin_required_current_admin_generate
    @pid_required_target_post_generate
    def post(self,target_post,current_admin):
        parser = reqparse.RequestParser()
        parser.add_argument('passed', type=bool,required=True, help="通过与否不能为空")
        parser.add_argument('reason')
        data= parser.parse_args()

        target_post.checked=True
        target_post.passed=data['passed']

        check=QueryOneInstance(Check,{'pid':target_post.id})
        check.passed=data['passed']
        check.reason=data['reason']
        check.checked=True

        UpdateInstance(target_post)
        UpdateInstance(check)

        return ResponseSuccess("已审核")

